package com.bw.kf.lib_base.utlis.http

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
class RetrofitUtlis {
    companion object{
        val client= OkHttpClient.Builder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10,TimeUnit.SECONDS)
            .readTimeout(10,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                val token= SPUtils.getInstance().getString("token","")
                val request=it.request().newBuilder()
                    .addHeader("Content-Type","application/json")
                    .addHeader("Authorization",token)
                    .build()
                it.proceed(request)
            }
            .build()
        fun getRetrofit(): Retrofit {
            val retrofit=Retrofit.Builder()
                .client(client)
                .baseUrl(Count.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build()
            return retrofit
        }
    }
}